<?php
session_start();
$hostname="mysql-user.cse.msu.edu"; // Host name
$username="hewittry"; // Mysql username
$password="A39777266"; // Mysql password
$database="hewittry"; // Database name
$currPage = "search";
include("inc_header.php"); ?>

	<div id="content">
		<h2><a href="#">Search for Cars</a></h2>
		<div class="clearfix">
<?php
			if ($_SESSION["usertype"] == "dealer")
			{
?>
			<p>Below are listed all of the announcements you've posted with most recent first.</p>
<?php
			}
			else
			{
?>
			<p>Below are listed all the announcements in the Transportation Station with the most recent first.</p>
<?php
			}
?>
			<table style="width: 600px;">
			<?php
			
			$conn = new mysqli($hostname, $username, $password, $database);
		
			if ($_SESSION["usertype"] == "dealer")
			{
				$username = $_SESSION['username'];
				$query = "SELECT * FROM VehicleForSale WHERE NonAdmins_AllUsers_LogonID = '".$username."' ORDER BY timestamp DESC";
			}
			else
			{
				$query = "SELECT * FROM VehicleForSale ORDER BY timestamp DESC"; 
			}
			$result = $conn->query($query);
			
			while ($row = $result->fetch_assoc())
			{
			?>
				<tr>
					<td style="padding-right: 7px; vertical-align: top;">
						<img src="./upload/<?php echo $row['Photo']; ?>" style="float: left; width: 100px; height: 100px;" />
					</td><td>
						<a href="./viewCar.php?id=<?php echo $row["VehicleForSaleID"]; ?>"><strong><?php echo $row["Make"] . " " . $row["Model"] . " " . $row["VehicleYear"]; ?></strong></a><br />
						Price: $<?php echo $row["Price"]; ?><br />
						Owner: <?php echo $row["NonAdmins_AllUsers_LogonID"]; ?><br />
						Posted on: <?php echo date(' h:i:s A F j, Y', $row['timestamp']); ?><br />
						<br />
						<br />
					</td>
				</tr>
			<?php
			}
			?>
			</table>
			<br />
		</div>

	</div>

<?php include("inc_footer.php"); ?>
